home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / timeSlider.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  12.4 KB  |  411 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. // Alias|Wavefront Script File
  19. // MODIFY THIS AT YOUR OWN RISK
  20. //
  21. // Creation Date:  20 Februrary 1996
  22. //
  23.     
  24. //
  25. //  Procedure Name:
  26. //        playButtonStart, playButtonStepBackward, playButtonBackward
  27. //        playButtonStop, playButtonRecord, playButtonForward
  28. //        playButtonStepForward, playButtonEnd
  29. //
  30. //  Description:
  31. //      Procs that update the current time according to which
  32. //        playback control is pressed.
  33. //
  34. //  Input Arguments:
  35. //      None.
  36. //
  37. //  Return Value:
  38. //      None.
  39. //
  40. global proc playButtonStart() {
  41.     currentTime -edit `playbackOptions -query -min`;
  42. }
  43.  
  44. global proc playButtonStepBackward() {
  45.     float $by = `playbackOptions -query -by`;
  46.     float $curr = `currentTime -query`;
  47.     float $min = `playbackOptions -query -min`;
  48.     float $max = `playbackOptions -query -max`;
  49.  
  50.     if(( $curr != $min )
  51.     &&(( $curr - $by ) >= $min )
  52.     &&(( $curr - $by ) < $max ))
  53.     {
  54.         currentTime -edit ( $curr - $by );
  55.     }
  56.     else {
  57.         currentTime -edit $max;
  58.     }
  59. }
  60.  
  61. global proc playButtonBackward() {
  62.     int $isOscillate = (`playbackOptions -q -loop` == "oscillate");
  63.  
  64.     if(( `play -query -state` == 1 ) 
  65.     &&(( `play -query -forward` == 0 ) || $isOscillate ))
  66.     {
  67.         play -state off;
  68.     }
  69.     else {
  70.         float $by = `playbackOptions -query -by`;    
  71.         if( `currentTime -q` - $by < `playbackOptions -q -min` ) {
  72.             currentTime -e `playbackOptions -q -max`;
  73.         }
  74.  
  75.         global string $gTimeSliderTimeField;
  76.         global string $gPlayBackForwardButton;
  77.         global string $gPlayBackReverseButton;
  78.  
  79.         // We do this here since the callback that sets up the 
  80.         // images on the buttons won't get called if we're already
  81.         // playing back (forward) and hit the "backward" button;
  82.         // The "playingBack" condition will not have been changed!
  83.         // 
  84.         symbolButton -edit 
  85.             -image "timeplay.xpm" 
  86.             -annotation  "Play forwards. Pressing the ESC key will stop playback." $gPlayBackForwardButton; 
  87.         symbolButton -edit 
  88.             -image "timestop.xpm" 
  89.             -annotation "Stop playback.  Pressing the ESC key will also stop playback." $gPlayBackReverseButton; 
  90.         floatField -e -enable false $gTimeSliderTimeField;
  91.         
  92.         play -forward off;
  93.     }
  94. }
  95. global proc playButtonForward() {
  96.     global string $gTimeSliderTimeField;
  97.  
  98.     int $isOscillate = (`playbackOptions -q -loop` == "oscillate");
  99.  
  100.     if(( `play -query -state` == 1 ) 
  101.     &&(( `play -query -forward` == 1 ) || $isOscillate ))
  102.     {
  103.         play -state off;
  104.     }
  105.     else {
  106.         float $by = `playbackOptions -query -by`;    
  107.         if( `currentTime -q` + $by > `playbackOptions -q -max` ) {
  108.             currentTime -e `playbackOptions -q -min`;
  109.         }
  110.  
  111.         global string $gPlayBackForwardButton;
  112.         global string $gPlayBackReverseButton;
  113.         global string $gPlayBackSlider;
  114.  
  115.         // We do this here since the callback that sets up the 
  116.         // images on the buttons won't get called if we're already
  117.         // playing back (forward) and hit the "backward" button;
  118.         // The "playingBack" condition will not have been changed!
  119.         // 
  120.         symbolButton -edit 
  121.             -image "timestop.xpm" 
  122.             -annotation "Stop playback.  Pressing the ESC key will also stop playback." $gPlayBackForwardButton; 
  123.         symbolButton -edit 
  124.             -image "timerev.xpm" 
  125.             -annotation "Play backwards. Pressing the ESC key will stop playback." $gPlayBackReverseButton; 
  126.         floatField -e -enable false $gTimeSliderTimeField;
  127.         
  128.         play -forward on -sound `timeControl -q -s $gPlayBackSlider`;
  129.     }
  130. }
  131.  
  132. global proc playButtonStepForward() {
  133.     float $by = `playbackOptions -query -by`;
  134.     float $curr = `currentTime -query`;
  135.     float $min = `playbackOptions -query -min`;
  136.     float $max = `playbackOptions -query -max`;
  137.  
  138.     if(( $curr != $max ) 
  139.     &&(( $curr + $by ) <= $max )
  140.     &&(( $curr + $by ) > $min ))
  141.     {
  142.         currentTime -edit ( $curr + $by );
  143.     }
  144.     else {
  145.         currentTime -edit $min;
  146.     }
  147. }
  148.  
  149. global proc playButtonEnd() {
  150.     currentTime -edit `playbackOptions -query -max`;
  151. }
  152.  
  153. global proc int playbackStateChanged() {
  154.     global string $gPlayBackForwardButton;
  155.     global string $gPlayBackReverseButton;
  156.     global string $gTimeSliderTimeField;
  157.  
  158.     if( `isTrue playingBack` ) {
  159.         if(( `play -query -st` == 0) || `play -query -forward` == 1 ) {
  160.  
  161.             if( `symbolButton -exists $gPlayBackForwardButton` ) {
  162.                 symbolButton -edit 
  163.                     -image "timestop.xpm" 
  164.                     -annotation "Stop playback.  Pressing the ESC key will also stop playback." $gPlayBackForwardButton; 
  165.             }
  166.  
  167.             if( `symbolButton -exists $gPlayBackReverseButton` ) {
  168.                 symbolButton -edit 
  169.                     -image "timerev.xpm" 
  170.                     -annotation "Play backwards. Pressing the ESC key will stop playback." $gPlayBackReverseButton; 
  171.             }
  172.         }
  173.         else {
  174.             if( `symbolButton -exists $gPlayBackForwardButton` ) {
  175.                 symbolButton -edit 
  176.                     -image "timeplay.xpm" 
  177.                     -annotation  "Play forwards. Pressing the ESC key will stop playback." $gPlayBackForwardButton; 
  178.             }
  179.  
  180.             if( `symbolButton -exists $gPlayBackReverseButton` ) {
  181.                 symbolButton -edit 
  182.                     -image "timestop.xpm" 
  183.                     -annotation "Stop playback.  Pressing the ESC key will also stop playback." $gPlayBackReverseButton; 
  184.             }
  185.         }
  186.  
  187.         if( `floatField -exists $gTimeSliderTimeField` ) {
  188.             floatField -e -enable false $gTimeSliderTimeField;
  189.         }
  190.     }
  191.     else {
  192.         if( `symbolButton -exists $gPlayBackForwardButton` ) {
  193.             symbolButton -edit 
  194.                 -image "timeplay.xpm" 
  195.                 -annotation  "Play forwards. Pressing the ESC key will stop playback." $gPlayBackForwardButton; 
  196.         }
  197.  
  198.         if( `symbolButton -exists $gPlayBackReverseButton` ) {
  199.             symbolButton -edit 
  200.                 -image "timerev.xpm" 
  201.                 -annotation "Play backwards. Pressing the ESC key will stop playback." $gPlayBackReverseButton; 
  202.         }
  203.  
  204.         if( `floatField -exists $gTimeSliderTimeField` ) {
  205.             floatField -e -enable true $gTimeSliderTimeField;
  206.         }
  207.     }
  208.  
  209.     // Scripts attached to the "condition" command
  210.     // must return an int.
  211.     //
  212.     return 1;
  213. }
  214.  
  215. // Procedure Name: 
  216. //        timeSlider
  217. //    
  218. // Description:
  219. //        This implements the group of controls that represents the
  220. //        timeSlider.  The timeSlider can either be part of a window
  221. //        or in a window of its own.
  222. //
  223. // Input Arguments:
  224. //        The name of the layout that the timeSlider should add itself
  225. //        to.  If empty, then this script will create a window.
  226. //
  227. // Return Value:
  228. //        The name of the top level layout control.
  229. //            (Used for embedding within another window)
  230. //
  231. //global proc string timeSlider(string $parentName)
  232. {
  233.     global string $gTimeSliderForm;
  234.     global string $gPlayBackForwardButton;
  235.     global string $gPlayBackReverseButton;
  236.     global string $gPlayBackSlider;
  237.     global string $gTimeSliderTimeField;
  238.     
  239.     //    Create a layout appropriate for the Time slider.
  240.     //
  241.     string $timeSlider = `formLayout -parent $gTimeSliderForm`;
  242.  
  243.     //    Create a frame layout for the Time slider control.
  244.     //
  245.     string $timeFrame = `frameLayout
  246.         -parent         $timeSlider
  247.         -borderVisible  true
  248.         -borderStyle    "in"
  249.         -labelVisible   false
  250.         -collapse       false
  251.         -collapsable    false`;
  252.  
  253.     //    Create the Time slider control.
  254.     //    
  255.     $gPlayBackSlider = `timeControl -parent $timeFrame -height 26`;
  256.     
  257.     setParent $timeSlider;
  258.  
  259.     //    Create the Time field.
  260.     //
  261.     $gTimeSliderTimeField = `floatField
  262.         -annotation "Current Time: Set the current time"
  263.         -width      70
  264.         -precision  2`;
  265.     floatField -edit
  266.         -enterCommand ("setFocus " + $gTimeSliderTimeField)
  267.         $gTimeSliderTimeField; 
  268.  
  269.     //    Create a grid layout for the play back buttons.
  270.     //
  271.     string $grid = `gridLayout 
  272.         -width               224 
  273.         -numberOfRowsColumns 1 8 
  274.         -cellWidthHeight     28 28`;
  275.  
  276.     //    Create the play back buttons...
  277.     //
  278.     string $startButton = `symbolButton
  279.         -image       "timerew.xpm"
  280.         -annotation  "Go to start of playback range"
  281.         -command     "playButtonStart"`;
  282.  
  283.     string $stepBackButton = `symbolButton
  284.         -image       "timeend.xpm"
  285.         -annotation  "Step back one frame"
  286.         -command     "playButtonStepBackward"`;
  287.  
  288.     string $prevCmd = "currentTime -edit `findKeyframe -timeSlider -which previous`";
  289.     string $prevButton = `symbolButton
  290.         -image       "timeprev.xpm"
  291.         -annotation  "Step back one key"
  292.         -command     $prevCmd`;
  293.  
  294.     $gPlayBackReverseButton = `symbolButton
  295.         -image       "timerev.xpm" 
  296.         -annotation  "Play backwards. Pressing the ESC key will stop playback."
  297.         -command     "playButtonBackward"`;
  298.  
  299.     $gPlayBackForwardButton = `symbolButton
  300.         -image       "timeplay.xpm" 
  301.         -annotation  "Play forwards. Pressing the ESC key will stop playback."
  302.         -command     "playButtonForward"`;
  303.  
  304.     string $nextCmd = "currentTime -edit `findKeyframe -timeSlider -which next`";
  305.     string $nextButton = `symbolButton
  306.         -image       "timenext.xpm" 
  307.         -annotation  "Step forward one key"
  308.         -command     $nextCmd`;
  309.  
  310.     string $stepFwdButton = `symbolButton
  311.         -image       "timestart.xpm"
  312.         -annotation  "Step forward one frame"
  313.         -command     "playButtonStepForward"`;
  314.  
  315.     string $endButton = `symbolButton
  316.         -image       "timefwd.xpm" 
  317.         -annotation  "Go to end of playback range"
  318.         -command     "playButtonEnd"`;
  319.  
  320.     //    Make attachments for contents of Time slider.
  321.     //
  322.     formLayout -edit
  323.         -attachForm    $timeFrame  "top"    0
  324.         -attachForm    $timeFrame  "left"   1
  325.         -attachNone    $timeFrame  "bottom"
  326.         -attachControl $timeFrame  "right"  2 $gTimeSliderTimeField
  327.         
  328.         -attachForm    $gTimeSliderTimeField  "top"    5
  329.         -attachNone    $gTimeSliderTimeField  "left"
  330.         -attachNone    $gTimeSliderTimeField  "bottom"
  331.         -attachControl $gTimeSliderTimeField  "right"  2 $grid
  332.  
  333.         -attachForm    $grid       "top"    3
  334.         -attachNone    $grid       "left"
  335.         -attachNone    $grid       "bottom"
  336.         -attachForm    $grid       "right"  0
  337.         $timeSlider;
  338.  
  339.     //    Attach Time slider to parent.
  340.     //
  341.     formLayout -edit
  342.         -attachForm    $timeSlider "top"    0
  343.         -attachForm    $timeSlider "left"   0
  344.         -attachForm    $timeSlider "bottom" 0
  345.         -attachForm    $timeSlider "right"  0
  346.         $gTimeSliderForm;
  347.  
  348.     //    Add call back to current time changes...
  349.     //
  350.     scriptJob -permanent -parent $timeSlider -event "timeChanged" 
  351.         ( "floatField -edit -value `currentTime -query` " 
  352.             + $gTimeSliderTimeField );
  353.     
  354.     //    Add callbacks playback controls...
  355.     //
  356.     floatField -edit -value `currentTime -query` 
  357.         -changeCommand ("currentTime " + 
  358.                         "`floatField -query -value " 
  359.                         + $gTimeSliderTimeField + "`; " +
  360.                         "setFocus `paneLayout -query -pane1 viewPanes`;")
  361.         $gTimeSliderTimeField;
  362.  
  363.     //  Register sound scrub callbacks on the timeControl widget.
  364.     //
  365.     timeControl -e -pc "timeControl -e -beginScrub $gPlayBackSlider" 
  366.         -rc "timeControl -e -endScrub $gPlayBackSlider" $gPlayBackSlider;
  367.  
  368.     // Make sure the play controls are in synch with playback
  369.     //
  370.     condition -dependency playingBack 
  371.               -script playbackStateChanged playbackIconsCondition;
  372.  
  373.     // Attach a popup menu to the timeslider area
  374.     //
  375.     TimeSliderMenu($timeSlider);
  376.  
  377.     setUIComponentStateCallback(
  378.         "Time Slider", "timeSliderVisibilityStateChange");
  379. }
  380.  
  381. global proc int timeSliderVisibilityStateChange(
  382.     int    $newState,
  383.     string $layout)
  384. //
  385. //    Description:
  386. //        This procedure is called whenever the visibility state of the 
  387. //        Time Slider is changed.
  388. //
  389. //    Arguments:
  390. //        newState - The new visibile state of the Time Slider.
  391. //
  392. //        layout - The parent layout for the Time Slider.
  393. //
  394. //    Returns:
  395. //        true - If the change of state is to be allowed.
  396. //
  397. //        false - If the state change is rejected.
  398. //
  399. {
  400.     int $result = true;
  401.  
  402.     //    Defer these commands because this proc is called when the visibility
  403.     //    state is about to change. This proc must return true to accept 
  404.     //    the state change. After this proc returns then restore the
  405.     //    panel focus and update the pref menu.
  406.     //
  407.     evalDeferred("restoreLastPanelWithFocus(); updatePrefsMenu();");
  408.  
  409.     return $result;
  410. }
  411.